<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="应付汇总表" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doSearch(){
		var year=document.getElementById("year").value;
		if(year==null || year==''){
			ShowAlert('提示框','请选择年份',200,100);
			return;
		}
		var tsId=document.getElementById("ts_id").value;
		window.location="/finance/PayableCount.ihtm?year="+year+"&ts_id="+tsId;
	}
	function getSearchCondition(){
		var str="year=${year}&ts_id=${tsId}";
		return str;
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
	}
	function doDownload(){
		var str=getSearchCondition();
		window.location="/finance/PayableCount.ihtm?content_type=EXCEL&"+str;
	}
	function getEndDate(month){
		if(month==0){
			month=12;
		}
		var d=new Date(${year},month,1);//下月的1号（month从0开始的）
		d.setDate(d.getDate()-1);
		return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	}
	function getStartDate(month){
		if(month==0){
			return "${year}-01-01";
		}else{
			return "${year}-"+month+"-01";
		}
	}
	function showCooList(month){
		var startDate=getStartDate(month);
		var endDate=getEndDate(month);
		var str="search_type=1&cb_cooper_date=1&start_date="+startDate+"&end_date="+endDate+"&cb_examine=1&examined=Y";
		var tsId="${tsId}";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1280,600,"/cooper/CooperBillSearchResult.ihtm?"+str);
	}
	function showPurList(month){
		var startDate=getStartDate(month);
		var endDate=getEndDate(month);
		var str="search_type=1&cb_pur_date=1&start_date="+startDate+"&end_date="+endDate;
		var tsId="${tsId}";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1024,600,"/purchase/PurchaseDetailSearchResult.ihtm?"+str);
	}
	function showPayableList(month,type){
		var startDate=getStartDate(month);
		var endDate=getEndDate(month);
		var tsId="${tsId}";
		if(type=='COOPER'){
			var str="search_type=1&cb_coo_date=1&start_date="+startDate+"&end_date="+endDate;
			if(tsId!="" && tsId!="0"){
				str=str+"&cb_ts=1&ts_id="+tsId;
			}
			showWin(1024,600,"/cooper/CooperBillListForPay.ihtm?"+str);
		}else{
			var str="search_type=1&cb_pur_date=1&start_date="+startDate+"&end_date="+endDate;
			if(tsId!="" && tsId!="0"){
				str=str+"&cb_ts=1&ts_id="+tsId;
			}
			showWin(1024,600,"/purchase/PurchaseBillListForPay.ihtm?"+str);
		}
	}
</script>
</head>
<c:set var="showLink" value="Y" />
<c:if test="${fn:indexOf(currentUser.privs,';NO_EARL_DATA;')!=-1}">
	<c:set var="showLink" value="N" />
</c:if>
<body oncontextmenu="return false" onLoad="doInit();" class="sheet" style="text-align:center;">
<div class="sheet-main" style="width:860px;text-align:left;margin:auto;">
  <div class="sheet-top">
    <div class="content">
      <h2>应付汇总表</h2>
      <p>统计每月采购外协的已付款、应付款</p>
    </div>
  </div>
  <div class="sheet-list">
    <div class="search-business">
      <div class="content">
        <table width="100%">
          <tbody>
            <tr>
              <td align="right">
              	年度：
              	<select name="year" id="year">
					<c:forEach var="item" begin="2010" end="${currentYear}">
						<option value="${item}" <c:if test="${year==item}">selected</c:if>>${item}</option>
					</c:forEach>
				</select>
				账套：
				<select name="ts_id" id="ts_id">
					<option value="0">==请选择账套==</option>
					<c:forEach var="item" items="${tsList}">
						<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
					</c:forEach>
				</select>
				<input type="button"  value=" 查 询" onClick="doSearch();"  class="buttom search-but">
				<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';UN_PAY_SEAR;')!=-1}">
					<a href="javascript:showWin(900,600,'/finance/PayableList.ihtm');">按供应商.外协商查询应付款</a>
				</c:if>
              </td>
            </tr>    
            </tbody>      
        </table>      	 
      </div>
      <div class="table-list">
        <table width="100%">
          	<tr>			
				<th  width="10%" rowspan="2">月份</th>
				<th  width="10%" rowspan="2">+采购</th>
				<th  width="10%" rowspan="2">+外协</th>
				<th  width="20%" colspan="2">+调账金额</th>
				<th  width="20%" colspan="2">-已付金款</th>
				<th  width="30%" colspan="3">=当月应付款</th>
			</tr>
			<tr>			
				<th  width="10%">采购</th>
				<th  width="10%">外协</th>
				<th  width="10%">采购</th>
				<th  width="10%">外协</th>
				<th  width="10%">采购</th>
				<th  width="10%">外协</th>
				<th  width="10%">小计</th>
			</tr>
			<c:forEach var="item" items="${list}" varStatus="i">
				<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
				<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
				<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
					<td>
						<input type="radio" name='query_checkbox' value="${i.index+1}" style="display:none">
						${i.index+1}
					</td>
					<td><c:if test="${showLink=='Y'}"><a href="javascript:showPurList(${i.index+1});"></c:if><commonTag:parseBigDecimal source="${item[0]}" /><c:if test="${showLink=='Y'}"></a></c:if></td>
					<td><c:if test="${showLink=='Y'}"><a href="javascript:showCooList(${i.index+1});"></c:if><commonTag:parseBigDecimal source="${item[1]}" /><c:if test="${showLink=='Y'}"></a></c:if></td>
					<td><commonTag:parseBigDecimal source="${item[2]}" /></td>
					<td><commonTag:parseBigDecimal source="${item[3]}" /></td>
					<td><commonTag:parseBigDecimal source="${item[4]}" /></td>
					<td><commonTag:parseBigDecimal source="${item[5]}" /></td>
					<td><c:if test="${showLink=='Y'}"><a href="javascript:showPayableList(${i.index+1},'PURCHASE');"></c:if><commonTag:parseBigDecimal source="${item[6]}" /><c:if test="${showLink=='Y'}"></a></c:if></td>
					<td><c:if test="${showLink=='Y'}"><a href="javascript:showPayableList(${i.index+1},'COOPER');"></c:if><commonTag:parseBigDecimal source="${item[7]}" /><c:if test="${showLink=='Y'}"></a></c:if></td>
					<td><commonTag:parseBigDecimal source="${item[8]}" /></td>
				</tr>
			</c:forEach>
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_TOTA;')==-1}">
			<tr>
				<th>合计</th>
				<th><c:if test="${showLink=='Y'}"><a href="javascript:showPurList(0);"></c:if><commonTag:parseBigDecimal source="${totalList[0]}" /><c:if test="${showLink=='Y'}"></a></c:if></th>
				<th><c:if test="${showLink=='Y'}"><a href="javascript:showCooList(0);"></c:if><commonTag:parseBigDecimal source="${totalList[1]}" /><c:if test="${showLink=='Y'}"></a></c:if></th>
				<th><commonTag:parseBigDecimal source="${totalList[2]}" /></th>
				<th><commonTag:parseBigDecimal source="${totalList[3]}" /></th>
				<th><commonTag:parseBigDecimal source="${totalList[4]}" /></th>
				<th><commonTag:parseBigDecimal source="${totalList[5]}" /></th>
				<th><c:if test="${showLink=='Y'}"><a href="javascript:showPayableList(0,'PURCHASE');"></c:if><commonTag:parseBigDecimal source="${totalList[6]}" /><c:if test="${showLink=='Y'}"></a></c:if></th>
				<th><c:if test="${showLink=='Y'}"><a href="javascript:showPayableList(0,'COOPER');"></c:if><commonTag:parseBigDecimal source="${totalList[7]}" /><c:if test="${showLink=='Y'}"></a></c:if></th>
				<th><commonTag:parseBigDecimal source="${totalList[8]}" /></th>
			</tr>
			</c:if>
		</table>
     </div>
 </div>
</div>
</div>
</body>
</html>
